#include "comm.h"
#define BAUD_RATE 4800
#define TIMER_PRESCALER 12
// Function to initialize UART
unsigned char Sec;
void UART_Init() {

	//PCON &= 0x7F;		//??????
	SCON = 0x50;		//8???,?????

	TMOD &= 0x0F;		//???????
	TMOD |= 0x20;		//???????
	TL1 = 0xFA;		//???????
	TH1 = 0xFA;		//???????
	ET1 = 0;		//?????%d??
	TR1 = 1;		//???1????
}

// Function to send a character through UART
void UART_SendChar(char c) {
    SBUF = c;     // Load character into UART transmit buffer
    while (!TI);  // Wait until transmission is complete
    TI = 0;       // Clear transmit interrupt flag
}

void sendCharByUART() {
    //UART_Init();  // Initialize UART
    // u8 i;
    // u8 character = 'A';  // Character to send

   while (1)
   {
     UART_SendChar(Sec);  // Send character through UART
     Sec++;
     delay(100);
   }

}

//UART_Receive_Data  function
u8 UART_Receive_Data() {
    u8 temp;
    while (!RI);  // Wait until reception is complete
    {
        /* code */
    }
    temp=SBUF;
    RI = 0;       // Clear receive interrupt flag
    
    return 'a';
}


void UART_Routine() interrupt 4
{

  P2_0 = 0;

    if (RI == 1) {
        RI = 0;
        //SBUF = 0xcc;
        sendCharByUART();
        // P2_0 = 0;
        //UART_Receive_Data();

    }
    if (TI == 1) {
        TI = 0;
    }
}